package com.polimi.meteocal.business.entity;

import java.io.Serializable;

import javax.persistence.*;

import java.util.List;


/**
 * The persistent class for the invite database table.
 * 
 */
@Entity
@NamedQueries({
@NamedQuery(name="Invite.findAll", query="SELECT i FROM Invite i"),
@NamedQuery(name="Invite.findForUser", query="SELECT i FROM Invite i "
													+ "WHERE i.id.receiver= :user"),
													
@NamedQuery(name="Invite.findbyEvent", query="SELECT i FROM Invite i, Event e "
													+ "WHERE i.id.eventId=e.id AND "
												    + "e.id = :eventId"),
@NamedQuery(name="Invite.loadUnreadInvites", query="SELECT i FROM Invite i WHERE i.id.receiver= :user AND i.isRead=0")


})
public class Invite implements Serializable {
	private static final long serialVersionUID = 1L;

	public static final String FIND_FOR_USER = "Invite.findForUser";
	public static final String FIND_BY_EVENT = "Invite.findbyEvent";
	public static final String LOAD_UNREAD_INVITES = "Invite.loadUnreadInvites";
	
	@EmbeddedId
	private InvitePK id;

	//bi-directional many-to-one association to Ack
	@OneToMany(mappedBy="invite",cascade={CascadeType.ALL})
	private List<Ack> acks;

	//bi-directional many-to-one association to Event
	@ManyToOne(cascade={CascadeType.ALL})
	private Event event;

	//bi-directional many-to-one association to User
	@ManyToOne
	@JoinColumn(name="SENDER")
	private User user1;

	//bi-directional many-to-one association to User
	@ManyToOne
	@JoinColumn(name="RECEIVER")
	private User user2;

	private boolean isRead;
	
	public Invite() {
	}

	public InvitePK getId() {
		return this.id;
	}

	public void setId(InvitePK id) {
		this.id = id;
	}

	public List<Ack> getAcks() {
		return this.acks;
	}

	public void setAcks(List<Ack> acks) {
		this.acks = acks;
	}

	public Ack addAck(Ack ack) {
		getAcks().add(ack);
		ack.setInvite(this);

		return ack;
	}

	public Ack removeAck(Ack ack) {
		getAcks().remove(ack);
		ack.setInvite(null);

		return ack;
	}

	public Event getEvent() {
		return this.event;
	}

	public void setEvent(Event event) {
		this.event = event;
	}

	public User getUser1() {
		return this.user1;
	}

	public void setUser1(User user1) {
		this.user1 = user1;
	}

	public User getUser2() {
		return this.user2;
	}

	public void setUser2(User user2) {
		this.user2 = user2;
	}

	public boolean isRead() {
		return isRead;
	}

	public void setRead(boolean isRead) {
		this.isRead = isRead;
	}

}